var overlay;
var modaldialog;

var menus = {};
menus['sheetbox'] = {'insert':'insertSheetbox', 'delete':'deleteSheetbox'};

function dialog(id) {
    overlay.setStyle("display", "block");
    //overlay.setStyle("opacity", "0.5");
    overlay.addEvent("click", closedialog);
	
    var request = new Ajax('getdialog', {method: 'post', data:'name=dialog_'+id+'.html', evalScripts:true, onSuccess: function() {
            modaldialog.setHTML(request.response['text']);
            modaldialog.setStyle("display", "block");
            //modaldialog.setStyle("opacity", "1.0");
        }
    });
    
    request.request();
}

function closedialog() {
    overlay.setStyle("display", "none");
    modaldialog.setStyle("display", "none");
}

function showMenu(e, context, objid) {
    event = new Event(e);

    pos = $(event.target).getPosition();
    var ul = new Element('ul', {
        'styles': {'left':pos.x, 'top':pos.y},
        'class': 'menu-context'
    });

    ul.addEvent('mouseenter', function(){
        ul.removeEvent('mouseenter');
        ul.addEvent('mouseleave', function() {
            ul.remove();
        })
    });

    for (voice in menus[context]) {
        var li = new Element("li", {
            'onclick': menus[context][voice]+'()',
            'class': 'voice-menu-context'
        });
        li.setText(voice);
        li.injectInside(ul);
    }

    ul.injectBefore(event.target);
}